#include <iostream>
#include <memory>
using std::cout;
using std::endl;
using std::shared_ptr;
using std::weak_ptr;

void test(){
    
    shared_ptr<int> sp(new int(10));
    cout << sp.use_count() << endl;
    //weak_ptr不会增加引用计数
    weak_ptr<int> wp(sp);
    cout << wp.use_count() << endl;
    //lock()可以把weak_ptr转为shared_ptr
    shared_ptr<int> sp2 = wp.lock();
    cout << sp2.use_count() << endl;
}

int main()
{
    

    test ();
    return 0;
}

